﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreDB.Extensions
{
    public static class StringExtension
    {
        public static bool IsValid(this string str)
        {
            return !string.IsNullOrWhiteSpace(str);
        }
        /// <summary>
        /// 粗略地字符串比较。该方法忽略字符串首尾空白、大小写以及全半角。
        /// </summary>
        /// <param name="str"></param>
        /// <param name="another"></param>
        /// <returns></returns>
        public static bool EqualRoughly(this string str, string another)
        {
            if (!str.IsValid() || !another.IsValid())
                return false;

            return string.Compare(str.Trim(), another.Trim(), CultureInfo.CurrentCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth) == 0;
        }

    }
}
